


const { response } = require('express')
const express = require('express')
const path = require('path')
const request = require('request')


const app = express()
// 设置ejs引擎
app.set('view engine', 'ejs')
app.use('/public',express.static(path.join(__dirname, './public')))

app.get('/', (req, res) => {
    console.log(`aaaa`);
    // res.render('newslist',{news:})
    request({
        type: "get",
        url: "http://v.juhe.cn/toutiao/index?key=807f10d5da886d846acdde0d7c34024d&type=top",
        headers:{
            'Content-Type':'application/json'
        },
        // data: JSON.stringify({
        //     type: 'top',
        //     key: '807f10d5da886d846acdde0d7c34024d'
        // }),
    },(err,ress,body)=>{
        // console.log(body);
        let news = JSON.parse(body).result.data
        res.render('newslist',{news})
    })
})


app.listen(3000, () => {
    console.log(`服务已启动...`);
})